package test.com.sms.selenium.singlepoint.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;


public class SpIncidentEditSATabPageUtil extends SeleniumPageUtil {

	public final static By IESA_LINK_SAVE = By.id("IncAddress1_btnSave");
	public final static By IESA_TD_ADDRESS = By.xpath("//*[@id='IncAddress1_trAddr']/td[1]");
	public final static By IESA_SELECT_ADDRESS = By.id("IncAddress1_cboAddressID");
	public final static By IESA_LINK_NEW_ADDRESS = By.id("IncAddress1_btnAddressNew");
	public final static By IESA_LINK_EDIT_ADDRESS = By.id("IncAddress1_btnAddressEdit");
	public final static By IESA_SPAN_ADDRESS_DETAIL = By.id("IncAddress1_lblAddress");
	public final static By IESA_TD_ADDRESS_DEL = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[2]/td[2]");
	public final static By IESA_TD_WAREHOUSE = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[3]/td[1]");
	public final static By IESA_INPUT_WAREHOUSE = By.id("IncAddress1_txtWarehouse");
	
	public static void enterSATab(String incidentId){
		// login into homepage
		SpSearchPageUtil.enter();
		// current window handle
		// make sure search button and incident id input text show
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_BUTTON_SEARCH)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_MAIN_INPUT_INCIDENT_ID)));
		// click the incident id link to enter the edit page
		SpIncidentEditPageUtil.enterIncidentID(incidentId);
		//click Assets link to enter incident/Asset edit page
		SeleniumUtil.click(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_LINK_TAB_SERVICE_ADDRESS));
		waitForPageToLoad();
	}
	public static void waitForPageToLoad(){
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.waitOnElements(new By[]{
				IESA_LINK_NEW_ADDRESS, IESA_SELECT_ADDRESS, IESA_LINK_EDIT_ADDRESS,IESA_LINK_SAVE
			});
	}
}
